#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
测试 @main 装饰器处理功能
"""

from tests.pytests.helpers.codegen_helpers import compile_source, assert_code_contains

# 测试代码：包含 @main 装饰器的函数
test_code = """
from mcpy.decorators import main
from mc.types import char_ptr, Pointer

@main()
def _main(argc: int, argv: Pointer[char_ptr]) -> int:
    print("Hello, MCPy!")
    return 0

def regular_function() -> str:
    return "test"
"""


def test_main_decorator_codegen():
    """测试 @main 装饰器的代码生成功能"""

    hpp, cpp = compile_source(test_code)

    # 验证头文件中不包含 main 函数声明
    assert "int main(" not in hpp, "头文件中不应包含 main 函数声明"

    expected_header_snippet = """
        std::string regular_function();
    """
    assert_code_contains(hpp, expected_header_snippet)

    expected_source = """
        int main(int argc, char** argv) {
            mcpy::print("Hello, MCPy!");
            return 0;
        }
        
        std::string regular_function() {
            return "test";
        }
    """
    assert_code_contains(cpp, expected_source)
